package com.moon.game.manager;

import java.util.List;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.log4j.Logger;

import com.moon.game.resource.model.AnimalChild;
import com.moon.game.util.IDGenerator;
import com.moon.game.vos.PlayerVo.Pet;

/**
 * @description 珍兽孵化资源管理
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-7-13 下午2:17:53
 */
public class AnimalChildMG {
	private static final Logger log = Logger.getLogger(AnimalChildMG.class);
	/**所有的珍兽孵化资源列表*/
	private static ConcurrentHashMap<Integer,AnimalChild> animalChildRes = new ConcurrentHashMap<Integer, AnimalChild>();
	
	/**获取珍兽孵化资源*/
	public static ConcurrentHashMap<Integer, AnimalChild> getAnimalChildRes() {
		return animalChildRes;
	}

	/** 根据id获取animalchild对象 */
	public final AnimalChild getAnimalChild(int id) {
		return animalChildRes.get(id);
	}

	private AnimalChildMG() {
	}
	public static AnimalChildMG instance = new AnimalChildMG();
	public void init() {
		log.debug("load animals child start...");
		loadAnimalsChild();
		log.debug("load animals child succ...");
	}
	
	private void loadAnimalsChild() {
		List<AnimalChild> animalsChild = DBManager.queryAllAnimalsChild();
		for (AnimalChild animalchild : animalsChild) {
			animalChildRes.put(animalchild.getId(), animalchild);
		}
	}
	

	/**
	 * 宠物工厂
	 * 
	 * @param childId
	 * @return
	 */
	public Pet petFactory(int childId) {
		AnimalChild childRes = getAnimalChild(childId);
		Pet pet = new Pet();
		pet.setPetId(childId);
		pet.setName(childRes.getName());
		pet.setPlayerPetId(IDGenerator.generateIntId());
		pet.setHierarchy(childRes.getHierarchy());
		pet.setCurMaturity(0);
		pet.setMaturity(childRes.getMaturity());
		pet.setPossessed(false);
		pet.setSex(new Random().nextInt(2) + 1);
		pet.setDescription(childRes.getDescription());
		int breedId = childRes.getBreedId() + new Random().nextInt(2);
		pet.setBreedId(breedId);
		pet.setBreedName(ItemMG.instance.getItem(breedId).getName());
		return pet;
	}
}
